<template>
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark" id="aaa" >
        <div class="container">
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
</button>
            <!-- <a class="navbar-brand" href="/" >King Of Bots</a> -->
            <!-- <router-link class="navbar-brand" :to="{name:'home'}">King Of Bots</router-link> -->
            <router-link class="navbar-brand" :to="{name:'home'}">速来击剑🤺!</router-link>
            <div class="collapse navbar-collapse" id="navbarText">
            <ul class="navbar-nav me-auto mb-2 mb-lg-0">
                <li class="nav-item">
                <!-- <a class="nav-link " aria-current="page" href="/pk">对战</a> -->
                <router-link :class="route_name=='pk_index' ? 'nav-link active' : 'nav-link' " :to="{name:'pk_index'}">快速匹配</router-link>
                </li>
                <li class="nav-item">
                <!-- <a class="nav-link " href="/record" >对局列表</a> -->
                <router-link :class="route_name=='record_index' ? 'nav-link active' : 'nav-link' " :to="{name:'record_index'}">对战记录</router-link>
                </li>
                <li class="nav-item">
                <!-- <a class="nav-link" href="/ranklist" >排行榜</a> -->
                <router-link :class="route_name=='ran_index' ? 'nav-link active' : 'nav-link' " :to="{name:'randlist_index'}">天梯排名</router-link>
                </li>
            </ul>


            <ul class="navbar-nav" v-if="$store.state.user.is_login">
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                        {{ $store.state.user.username }}
                    </a>
                    <ul class="dropdown-menu" aria-describedby="navbarDropdown">
                        <!-- <li><a class="dropdown-item" href="/user/bot">我的bot</a></li> -->
                        <router-link class="dropdown-item"  :to="{name:'user_bot_index'}">我的bot</router-link>
                        <li><hr class="dropdown-divider"></li>
                        <li><a class="dropdown-item" href="#" @click="logout">退出</a></li>
                    </ul>
                </li>
            </ul>

            <ul class="navbar-nav" v-else>
                <li class="nav-item ">
                    <router-link class="nav-link" :to="{name:'user_account_login'}" role="button" >
                        登陆
                    </router-link>
                </li>
                <li class="nav-item ">
                    <router-link class="nav-link" :to="{name:'user_account_register'}" role="button" >
                        注册
                    </router-link>
                </li>
            </ul>

            </div>
        </div>
</nav>
</template>

<script>
import { useRoute } from 'vue-router';
import {computed} from 'vue';
import {useStore} from 'vuex'


export default{
    setup(){
        const store =useStore();
        const route=useRoute();
        let route_name=computed(
            ()=>route.name
        )

        const logout= ()=>{
            store.dispatch("logout");
        }

        return{
            route_name,
            logout
        }
    }

}
</script>

<style scoped>
    /* #aaa{
        background-color:white;
    } */

</style>